package com.huizhonglm.diap.ui.user;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.bruce.common.ActivityMgr;
import com.bruce.common.utils.EmptyUtil;
import com.bruce.common.utils.PatternUitl;
import com.huizhonglm.diap.R;
import com.huizhonglm.diap.core.utils.ToastUtil;
import com.huizhonglm.diap.ui.BaseActivity;

/**
 * 描述当前类的作用
 *
 * @author LiXiaoLong
 * @version 1.0
 * @since 2016-03-03 10:53
 */
public class InputPhoneNumActivity extends BaseActivity implements View.OnClickListener {

    private EditText phoneNumEdt;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityMgr.getInstance().pushActivity(InputPhoneNumActivity.this);
        setContentView(R.layout.activity_input_phone_num);
        setBackEvent(this, null);
        assignViews();
    }

    @Override
    protected void assignViews(){
        phoneNumEdt = (EditText) findViewById(R.id.phone_num_edt);
        View nextStapBtn = findViewById(R.id.next_stap_btn);
        View titleLogin = findViewById(R.id.title_login_txt);
        View emailRegBtn = findViewById(R.id.email_register_btn);
        TextView agreement = (TextView) findViewById(R.id.user_agreement_txt);
        agreement.setOnClickListener(this);
        nextStapBtn.setOnClickListener(this);
        titleLogin.setOnClickListener(this);
        emailRegBtn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.next_stap_btn:
                String phone = phoneNumEdt.getText().toString().trim();
                if (EmptyUtil.isEmpty(phone)){
                    ToastUtil.makeTextShort("请输入手机号码");
                    return;
                } else {
                    if (!PatternUitl.isPhone(phone)) {
                        ToastUtil.makeTextShort("请输入有效的手机号码");
                        return;
                    }
                }
                Intent intent = new Intent(this, InputPhoneCodesActivity.class);
                intent.putExtra("phoneNumber", phone);
                startActivity(intent);
                break;
            case R.id.title_login_txt:
                ActivityMgr.getInstance().popActivity(InputPhoneNumActivity.class);
                onBackPressed();
                break;
            case R.id.email_register_btn:
                startActivity(new Intent(this, InputEmailAddrActivity.class));
                break;
            case R.id.user_agreement_txt:
                startActivity(new Intent(this, PrivacyRulesActivity.class));
                break;
        }
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        finish();
    }
}
